{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "他会飞\n"
     ]
    }
   ],
   "source": [
    "from abc import abstractmethod ,ABCMeta\n",
    "class AnimalInSky(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def walk(self):\n",
    "        pass\n",
    "class AnimaInwater(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def swim(self):\n",
    "        pass\n",
    "class Tiger(AnimalInSky):\n",
    "    def walk(self):\n",
    "        print('他会飞')\n",
    "obj=Tiger()\n",
    "obj.walk()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n",
      "hello\n",
      "987\n",
      "<__main__.A object at 0x000001FB2218DE10>\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    def test(self):\n",
    "        return 'hello'\n",
    "class B:\n",
    "    def test(self):\n",
    "        return 123\n",
    "class C:\n",
    "    def __init__(self):\n",
    "        self.a=A()\n",
    "        self.a.test()\n",
    "    def test(self):\n",
    "        return 987\n",
    "print(B().test())\n",
    "print(C().a.test())\n",
    "print(C().test())\n",
    "print(C().a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "微信支付了100元\n",
      "支付宝支付了4546元\n"
     ]
    }
   ],
   "source": [
    "from abc import abstractmethod,ABCMeta\n",
    "class Payment(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def pay(self):\n",
    "        pass\n",
    "class Alipay(Payment):\n",
    "    def __init__(self,money):\n",
    "        self.money=money\n",
    "    def pay(self):\n",
    "        print('支付宝支付了%s元'%self.money)\n",
    "class watpay(Payment):\n",
    "    def __init__(self,money):\n",
    "        self.money=money\n",
    "    def pay(self):\n",
    "        print('微信支付了{}元'.format(self.money))\n",
    "if __name__=='__main__':\n",
    "    obj=watpay(100)\n",
    "    obj.pay()\n",
    "    \n",
    "    obj=Alipay(4546)\n",
    "    obj.pay()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
